/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 晓星航
 * Date: 2022-10-19
 * Time: 15:00
 */

class TestDemo1{
    public int a;
    public static int count;
}
class Person {
    private String s;
    public int age;
    public String sex;
    public String name;
    public static int grade;
    public void eat() {
        System.out.println("吃饭！");
    }
    public void sleep() {
        System.out.println("睡觉！");
    }
    public void print() {
        System.out.println("姓名："+name+"  年龄："+age+"  性别："+sex);
    }
    public void show() {
        System.out.println("我叫" + name + ", 今年" + age + "岁");
    }

    public String getS() {
        return s;
    }

    public void setS(String s) {
        this.s = s;
    }

    @Override
    public String toString() {
        return "Person{" +
                "age=" + age +
                ", sex='" + sex + '\'' +
                ", name='" + name + '\'' +
                '}';
    }
}
class Person1 {
    private String name;//实例成员变量
    private int age;

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void setName(String name){
        //name = name;//不能这样写
        this.name = name;//this引用，表示调用该方法的对象
    }
    public String getName(){
        return name;
    }

    public void show(){
        System.out.println("name: "+name+" age: "+age);
    }
}
class Person3 {

    private String name;//实例成员变量
    private int age;
    private String sex;
    //默认构造函数 构造对象
    public Person3() {
        this.name = "caocao";
        this.age = 10;
        this.sex = "男";
    }
    //带有3个参数的构造函数
    public Person3(String name,int age,String sex) {
        this.name = name;
        this.age = age;
        this.sex = sex;
    }
    public void show(){
        System.out.println("name: "+name+" age: "+age+" sex: "+sex);
    }
}

public class TestDemo {
    public static void main(String[] args) {
        Person3 p1 = new Person3();//调用不带参数的构造函数 如果程序没有提供会调用不带参数的构造函数
        p1.show();
        Person3 p2 = new Person3("zhangfei",80,"男");//调用带有3个参数的构造函数
        p2.show();
    }
    public static void main6(String[] args) {
        Person1 person = new Person1();
        person.setName("qiqi");
        person.setAge(18);
        person.show();
    }
    public static void main5(String[] args) {
        Person person = new Person();
        System.out.println(person);
    }
    public static void main4(String[] args) {
        Person person2 = new Person();
        person2.name = "李四";
        person2.age = 20;
        person2.show();
    }
    public static void main3(String[] args) {
        Person person = new Person();
        System.out.println(person.name);
        System.out.println(person.age);
    }
    public static void main2(String[] args) {
        TestDemo1 t1 = new TestDemo1();
        t1.a++;
        TestDemo1.count++;
        System.out.println(t1.a);
        System.out.println(TestDemo1.count);
        System.out.println("============");
        TestDemo1 t2 = new TestDemo1();
        t2.a++;
        TestDemo1.count++;
        System.out.println(t2.a);
        System.out.println(TestDemo1.count);
    }
    public static void main1(String[] args) {
        Person person = new Person();
        person.eat();
        person.sleep();
        person.age = 18;
        person.sex = "男";
        person.name = "huangneng";
        person.print();
        Person person1 = new Person();
        person1.grade++;
        System.out.println(person1.grade);
        Person person2 = new Person();
        person2.grade++;
        System.out.println(person2.grade);
        Person person3 = new Person();
    }
}